package org.zhao.nettydemos.lab09;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Auther: xiaohui.zhao
 * @Date: 2021/9/17 17:09
 * @Description:  测试 ScheduledThreadPoolExecutor
 */
public class ScheduledThreadPoolExecutorTest {

    public static void main(String[] args) throws InterruptedException {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(3);

        scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("测试 scheduledThreadPoolExecutor");
            }
        },1,1, TimeUnit.SECONDS);

        // 主线程休眠10秒
        Thread.sleep(10000);

        System.out.println("正在关闭线程池");

        // 关闭线程池
        scheduledExecutorService.shutdown();;

        boolean isClosed;

        do{
            isClosed = scheduledExecutorService.awaitTermination(1,TimeUnit.DAYS);
            System.out.println("正在等待线程池中的任务完成");
        }while(!isClosed);

        System.out.println("所有线程执行完毕 ， 线程池关闭");

    }

}